package ai

import (
	"errors"
	"fmt"

	http_label_center "gobase/http_work_flow/label_center"
	emox "gobase/http_work_flow/label_center/ai/emo"
)

// 数据转绘制
func Data2EMOImage(value *emox.RespEMOImage) (_frame http_label_center.Tag, _err error) {
	var metas = make([]http_label_center.Meta, 0)
	if !value.Success {
		_err = fmt.Errorf("情感分析失败 %+v", value)
		return
	}
	if len(value.Data) == 0 {
		_err = errors.New("情感分析 没有结果")
		return
	}
	for _, v := range value.Data {
		var meta = http_label_center.Meta{
			X:      int64(v.FaceRectangle.Box[0]),
			Y:      int64(v.FaceRectangle.Box[1]),
			Remark: fmt.Sprintf("情感分析:%f", v.FaceRectangle.Confidence),
			TypeId: 1,
			// ProtoWidth:  1920,
			// ProtoHeight: 1080,
			Rect: &http_label_center.Rect{

				Width:  int64(v.FaceRectangle.Box[2] - v.FaceRectangle.Box[0]),
				Height: int64(v.FaceRectangle.Box[3] - v.FaceRectangle.Box[1]),
				Text:   fmt.Sprintf("%+v", v.FaceID.EmotionRate.EmotionList),
				Center: false,
			},
		}
		metas = append(metas, meta)
		_frame = http_label_center.Tag{
			Metas: metas,
			AbsoluteTime: &http_label_center.AbsoluteTime{
				CenterUnixMs: value.CenterUnixMs, //TODO: 时间戳
				DurationMs:   2000,
			},
		}
	}

	return
}
